# author: axin
# date: 2021/4/23 16:44
# description:
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from django.contrib.auth.models import Group

from meiduo_admin.serialziers.admin import AdminSerializer
from meiduo_admin.serialziers.group import GroupSerializer
from meiduo_admin.utils import PageNum
from users.models import User


class AdminView(ModelViewSet):
    queryset = User.objects.filter(is_staff=True)
    serializer_class = AdminSerializer
    pagination_class = PageNum
    permission_classes = [IsAdminUser]

    def simple(self, request):
        """
            查询分组信息
        :param request:
        :return:
        """
        # 1. 查询分组表
        data = Group.objects.all()
        # 2. 返回分组信息
        ser = GroupSerializer(data, many=True)
        return Response(ser.data)
